const baseurl='https://devapi.qweather.com/v7/weather/now?key=b7c81e1dabd749eda4003517e1554a31&location='
const baseurls='https://devapi.qweather.com/v7/weather/3d?key=b7c81e1dabd749eda4003517e1554a31&location='
Page({
  data:{
    city:'',
    weather:'',
    dampness:'',
    windpower:'',
    pressure:'',
    temperature:'',
    direct:'',
    yi:'',
    er:'',
    san:'',
    latitude:0,
    longitude:0,
  },
  input(e){
    //console.log(e)
    this.setData({
      city:e.detail.value
    })
  },
  search(){
    let city = this.data.city
    let latitude = this.data.latitude
    let longitude = this.data.longitude
    let url = `${baseurl}${longitude},${latitude}`
    //console.log(url)
    let that = this
    wx.request({
      url,
      success(e){
        
        console.log(e)
        let {temp,windDir,windScale,text,humidity,dew,pressure} = e.data.now
        that.setData({
          city:city,
          weather:text,
          dampness:humidity,
          windpower:windScale,
          pressure:pressure,
          temperature:temp,
          direct:windDir
        })
      }
    })
    url = `${baseurls}${longitude},${latitude}`
    wx.request({
      // 发送请求地址
      url,
      // 成功调用此回调函数
      success(e){
          // 查看返回的各种信息，ajax里是respondText、respondXML、JSON.parse(data)回调里的data;
          console.log(e)
           var yi = e.data.daily[0]
           var er = e.data.daily[1]
           var san = e.data.daily[2]
          that.setData({
             yi:yi,
             er:er,
             san:san,
      
          })
      }
  })
},
onLoad(){
  let that = this
  wx.getLocation({
    success(e){
      let {latitude,longitude} = e
      that.setData({
        latitude,longitude
      })
    }
  })
}
})

